<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@page import="org.madmac.join.PlacaRedeXMaquinas"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
			pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- VERIFICA SE O USUÁRIO ESTÁ COM O COOKIE VÁLIDO, SENÃO O REDIRECIONA PARA A PÁGINA DE LOGIN -->
<%@ include file="/log/verify_login.jsp" %>

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Resultado da Pesquisa</title>
      <link rel="icon" href="/madmac/favicon.ico" type="image/x-icon" />
      <link rel="shortcut icon" href="/madmac/favicon.ico" type="image/x-icon" />
      <link rel="stylesheet" href="/madmac/menu_madmac_files/cbcscbmenu_madmac.css" type="text/css" />
		<link rel="stylesheet" href="/madmac/estilos/madmac_tables.css" type="text/css" />
      <link rel="stylesheet" href="/madmac/estilos/madmac_inputs.css" type="text/css" />
      <script type="text/javascript" src="/madmac/madmacproject.js"></script>
		<!-- PAGINAÇÃO VIA AJAX -->
		<style type="text/css" title="currentStyle">
			@import "/madmac/paginacao/css/demo_page.css";
			@import "/madmac/paginacao/css/demo_table.css";
		</style>
		<script type="text/javascript" language="javascript" src="/madmac/paginacao/js/jquery.js"></script>
		<script type="text/javascript" language="javascript" src="/madmac/paginacao/js/jquery.dataTables.js"></script>
		<script type="text/javascript" charset="utf-8">
			$(document).ready(function() {
				$('#example').dataTable();
			} );
		</script>

   </head>
   <body onload="document.getElementById('search_mac').focus()">
      <div class="logotype"><img src="/madmac/madmac-logo-1.0.1.png" height="120%" alt="MAD MAC"></div>

      <div class="menu_principal">
			<%@ include file="/common_pages/menu.jsp" %>
      </div>

      <div class="search_mac">
			<%@include file="/common_pages/search_mac.jsp" %>
      </div>

      <div class="corpo">
			<p></p>
			<%
		String search_mac;
		try {

			search_mac = request.getParameter("part_of_mac");

			int search_id_sala;
			int search_faixa_ip;

			try {
				search_id_sala = Integer.parseInt(request.getParameter("sala"));
			} catch (Exception e) {
				search_id_sala = 0;
			}

			try {
				search_faixa_ip = Integer.parseInt(request.getParameter("faixa_ip"));
			} catch (Exception e) {
				search_faixa_ip = 0;
			}

			List<PlacaRedeXMaquinas> mac_result = new ArrayList<PlacaRedeXMaquinas>();

			if (search_mac.length() < 17) {

				/* realizar busca por parte do MAC */
				mac_result = PlacaRedeXMaquinas.getInstance().searchByHalfOfMAC(search_mac.toLowerCase(), search_id_sala, search_faixa_ip);

				if (mac_result.size() == 0) {
			%>
			<p><br/></p>
         <table width="50%" align="center" border="1" cellpadding="0" cellspacing="0" rules="rows" class="main_table">
            <tr class="alert_cell">
               <td align="center">
                  <img src="/madmac/icons/file_alert.png" align="middle" width="54px" alt="">
               </td>
               <td>Endereço MAC não encontrado . . .</td>
            </tr>
				<tr>
               <td class="data_cell" align="right" colspan="2">
                  <input type="button" value="Voltar" class="bBack" onclick="javascript:history.go(-1)">
               </td>
				</tr>
         </table>
			<%					  } else {
			%>
			<p><br></p>
			<table width="96%" align="center" border="1" cellpadding="5" cellspacing="0" rules="rows" class="main_table">
				<tr class="meta_line">
					<td width="8%"></td>
					<td>Lista de Endereços MAC</td>
					<td width="15%" align="center">
						<a href="/madmac/mac/search_part_of_mac.jsp">
							<img src="/madmac/icons/view.png" border="0" title=" Nova Pesquisa " alt="">
						</a>&nbsp;
						<a href="/madmac/mac/adicionar_mac.jsp">
							<img src="/madmac/icons/key_add.png" border="0" title=" Adicionar Novo MAC " alt="">
						</a>
					</td>
				</tr>
			</table>
			<br/>
			<div id="demo">
				<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
					<thead>
						<tr>
							<th width="5%">#</th>
							<th>Tombamento</th>
							<th width="15%">MAC</th>
							<th width="10%">IP</th>
							<th>Setor</th>
							<th align="center">S.O.</th>
							<th>Responsável</th>
							<th>Faixa</th>
							<th>Wireless?</th>
							<th width="5%"></th>
						</tr>
					</thead>
					<tbody>
						<%
								  for (int i = 0; i < mac_result.size(); i++) {

									  PlacaRedeXMaquinas mac = mac_result.get(i);
									  String rede = "";
									  String status_rede = "";
									  if (mac.isRede_sem_fio()) {
										  rede = "tick";
										  status_rede = "Yes";
									  } else {
										  rede = "cross";
										  status_rede = "No";
									  }
						%>
						<tr>
							<td><%=i + 1%></td>
							<td><%=mac.getTombamento()%></td>
							<td><%=mac.getMac()%></td>
							<td><%=mac.getIp()%></td>
							<td class="cap_cell"><%=mac.getSetor().toLowerCase()%></td>
							<td>
								<img src="/madmac/icons/<%=mac.getSistema_op()%>.png" title=" <%=mac.getSistema_op()%> " alt="">
							</td>
							<td class="cap_cell"><%=mac.getResponsavel().toLowerCase()%></td>
							<td class="cap_cell"><%=mac.getFaixa()%></td>
							<td align="center">
								<img src="/madmac/icons/<%=rede%>.png" border="0" title="<%=status_rede%>" alt="<%=status_rede%>">
							</td>
							<td align="center" class="cmd_cell">
								<a href="/madmac/mac/editar_mac.jsp?mac=<%=mac.getMac()%>">
									<img src="/madmac/icons/key_pencil.png" border="0" title=" Editar " alt="">
								</a>
							</td>
						</tr>
						<%
								  }
						%>
					</tbody>
					<tfoot>
						<tr>
							<th class="cap_cell" colspan="10">MAD MAC beta 1.0</th>
						</tr>
					</tfoot>
				</table>
			</div>
			<p><br/><br/></p>
				<%
						  }
					  } else if (search_mac.length() == 17) {

						  /* realizar busca por mac completo utilizando o método searchMacDetails */
						  try {

							  PlacaRedeXMaquinas view_mac = PlacaRedeXMaquinas.getInstance().selectMacDetails(search_mac);
							  String rede = "";
				%>
			<p><br/></p>
			<table width="50%" align="center" border="0" cellpadding="12" cellspacing="0" rules="all" class="main_table">
				<tr>
					<td width="5%"></td>
					<td class="meta_cell">MAC Details</td>
					<td class="data_cell"><%=view_mac.getMac()%></td>
					<td width="5%"></td>
				</tr>
				<tr>
					<td></td>
					<td class="meta_cell">IP</td>
					<td class="data_cell"><%=view_mac.getIp()%></td>
					<td></td>
				</tr>
				<tr>
					<td></td>
					<td class="meta_cell">Rede Sem Fio?</td>
					<%
						if (view_mac.isRede_sem_fio()) {
							rede = "yes";
						} else {
							rede = "no";
						}
					%>
					<td class="data_cell">&nbsp;<img src="/madmac/icons/<%=rede%>.gif" alt="">&nbsp;<%=rede%></td>
					<td></td>
				</tr>
				<tr>
					<td></td>
					<td class="meta_cell">Setor</td>
					<td class="data_cell_Cap"><%=view_mac.getSetor()%></td>
					<td></td>
				</tr>
				<tr>
					<td></td>
					<td class="meta_cell">Responsável</td>
					<td class="data_cell_Cap"><%=view_mac.getResponsavel().toLowerCase()%></td>
					<td></td>
				</tr>
				<tr>
					<td></td>
					<td class="meta_cell">Sistema Operacional</td>
					<td class="data_cell"><%=view_mac.getSistema_op()%></td>
					<td></td>
				</tr>
			</table>
			<%
					} catch (Exception e) {
			%>
			<p><br/></p>
         <table width="45%" align="center" border="1" cellpadding="5" cellspacing="0" rules="rows" class="main_table">
				<tr class="alert_cell">
               <td align="center" width="15%"><img src="/madmac/icons/file_alert.png" align="middle" width="64px" alt=""></td>
					<td><%=e.getMessage()%></td></tr>
				<tr>
               <td class="data_cell" align="right" colspan="2">
                  <input type="button" value="Voltar" class="bBack" onclick="javascript:history.go(-1)">
               </td>
				</tr>
			</table>
			<%
					  }
				  }
			  } catch (Exception e) {
			%>
			<p><br/></p>
         <table width="45%" align="center" border="1" cellpadding="5" cellspacing="0" rules="rows" class="main_table">
				<tr class="alert_cell">
               <td align="center" width="15%"><img src="/madmac/icons/file_alert.png" align="middle" width="64px" alt=""></td>
					<td><%=e.getMessage()%></td></tr>
				<tr>
               <td class="data_cell" align="right" colspan="2">
                  <input type="button" value="Voltar" class="bBack" onclick="javascript:history.go(-1)">
               </td>
				</tr>
			</table>
			<br/>
			<%
		}
			%>
			<p></p>
      </div>
      <div class="footer_madmac">
			<%@include file="/common_pages/footer.jsp" %>
      </div>
   </body>
</html>